package com.boge.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.boge.modules.sys.entity.NoticeEntity;
import com.boge.modules.sys.service.NoticeService;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.R;



/**
 * 
 *
 * @author boge
 * @email dengpbs@163.com
 * @date 2023-05-31 23:44:03
 */
@RestController
@RequestMapping("sys/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("sys:notice:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = noticeService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/homeInfo")
    //@RequiresPermissions("sys:notice:info")
    public R homeInfo(){
        List<NoticeEntity> list = this.noticeService.list(new QueryWrapper<NoticeEntity>()
                .eq("state",0).orderByDesc("create_time"));

        return R.ok().put("notices", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("sys:notice:info")
    public R info(@PathVariable("id") Integer id){
		NoticeEntity notice = noticeService.getById(id);

        return R.ok().put("notice", notice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("sys:notice:save")
    public R save(@RequestBody NoticeEntity notice){
		noticeService.save(notice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("sys:notice:update")
    public R update(@RequestBody NoticeEntity notice){
		noticeService.updateById(notice);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("sys:notice:delete")
    public R delete(@RequestBody Integer[] ids){
		noticeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
